Skip to content

TestJumpToDateEndpoint: Add test for seamlessly paginating from /context start token#853

Merged
MadLittleMods merged 9 commits intomainfrom
madlittlemods/timestamp-to-event-paginate-from-start
May 1, 2026
Merged

TestJumpToDateEndpoint: Add test for seamlessly paginating from /context start token#853
MadLittleMods merged 9 commits intomainfrom
madlittlemods/timestamp-to-event-paginate-from-start

Conversation

@MadLittleMods
Copy link
Copy Markdown
Collaborator

@MadLittleMods MadLittleMods commented Mar 26, 2026

TestJumpToDateEndpoint: Add test for seamlessly paginating from /context start token

Follow-up to #852

Dev notes

COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh -run TestJumpToDateEndpoint

Todo

Pull Request Checklist

})

t.Run("can paginate after getting remote event from timestamp to event endpoint", func(t *testing.T) {
t.Run("can paginate backwards after getting remote event from timestamp to event endpoint (start)", func(t *testing.T) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail until element-hq/synapse#19611 is merged

})

t.Run("can paginate after getting remote event from timestamp to event endpoint", func(t *testing.T) {
t.Run("can paginate backwards after getting remote event from timestamp to event endpoint (start)", func(t *testing.T) {
Copy link
Copy Markdown
Collaborator Author

@MadLittleMods MadLittleMods Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to have a test for paginating from the start and end tokens from /context after getting an event from /timestamp_to_event.

Previously, we only had a test for end

Comment on lines -222 to 227
// Hit `/messages` until `eventA` has been backfilled and replicated across
// workers (the worker persisting events isn't necessarily the same as the worker
// serving `/messages`)
fetchUntilMessagesResponseHas(t, remoteCharlie, roomID, func(ev gjson.Result) bool {
return ev.Get("event_id").Str == eventA.EventID
t.Run("can paginate backwards after getting remote event from timestamp to event endpoint (end)", func(t *testing.T) {
t.Parallel()
roomID, eventA, eventB := createTestRoom(t, alice)
remoteCharlie.MustJoinRoom(t, roomID, []spec.ServerName{
deployment.GetFullyQualifiedHomeserverName(t, "hs1"),
})
Copy link
Copy Markdown
Collaborator Author

@MadLittleMods MadLittleMods Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the idea of the comment above fetchUntilMessagesResponseHas(...) is true, we're retrying the wrong endpoint. When you use /timstamp_to_event, it should backfill the event in the cases of asking the federation. Which means we should be retrying the /context request until we see the event (not /messages)

This functionality was maintained via the client.WithRetryUntil(...) on the /context request

}
}

func fetchUntilMessagesResponseHas(t *testing.T, c *client.CSAPI, roomID string, check func(gjson.Result) bool) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove fetchUntilMessagesResponseHas as it's now unused

@MadLittleMods MadLittleMods marked this pull request as ready for review March 27, 2026 00:06
@MadLittleMods MadLittleMods requested review from a team as code owners March 27, 2026 00:06
Copy link
Copy Markdown
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assuming /context -> /messages makes sense, and CI eventually passes.

Thank you for the detailed comments - they're especially helpful with such a complex topic.

MadLittleMods added a commit to element-hq/synapse that referenced this pull request May 1, 2026
The juicy details and explanation are in the diff itself.

Split out from #18873 in order
to fix paginating from
[MSC3871](matrix-org/matrix-spec-proposals#3871)
gap tokens actually backfilling history. To be clear, this is a good
change to make outside of the
[MSC3871](matrix-org/matrix-spec-proposals#3871)
use case. For example (as the new Complement test shows), fixes a
problem where if you try to paginate `/messages` from tokens returned by
`/context`, we could fail to backfill anything new and hide away
history.

Also fixes matrix-org/complement#853
@MadLittleMods MadLittleMods reopened this May 1, 2026
@MadLittleMods
Copy link
Copy Markdown
Collaborator Author

MadLittleMods commented May 1, 2026

(this was closed automatically by GitHub because the description in element-hq/synapse#19611 said this also fixes #853 which seems pretty bogus, closing PRs?!?!?)

Re-opening as we want to merge this ⏩

@MadLittleMods MadLittleMods merged commit bb8d0f0 into main May 1, 2026
4 checks passed
@MadLittleMods MadLittleMods deleted the madlittlemods/timestamp-to-event-paginate-from-start branch May 1, 2026 19:02
@MadLittleMods
Copy link
Copy Markdown
Collaborator Author

Thanks for the review @anoadragon453 🦑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants